#include <iostream>
#include <string>
#include <vector>

using namespace std;

// 1004. 最大连续1的个数 III
// https://leetcode.cn/problems/max-consecutive-ones-iii/description/

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int zeroCnt = 0;
        int left = 0;
        int ans = 0;
        int n = nums.size();
        for (int i = 0; i < n; i++){
            int curNum = nums[i];
            if(curNum == 0){
                zeroCnt++;
            }
            while(zeroCnt > k){
                if(nums[left++] == 0){
                    zeroCnt--;
                }
            }
            ans = max(ans, i - left + 1);
        }
        return ans;
    }
};

int main()
{
    return 0;
}